package com.lc.result;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author pet.team
 * @Description 分页类
 */
public class Page<T> implements Serializable {

    private static final long serialVersionUID = 5294589632707269745L;
    /** 默认页大小 */
    private static Integer DEFAULT_PAGE_SIZE = 10;
    private static Integer DEFAULT_PAGE_NO = 1;
    /** 当前页码 */
    private Integer pageNo;
    /** 每页的记录数 */
    private Integer pageSize = DEFAULT_PAGE_SIZE;
    /** 总记录数 */
    private long total;
    /** 总页数 */
    private Integer pages;
    /** 数据 */
    private List<T> list;
    /** 开始位置 */
    private Integer beginPos;

    public Page(List<T> list) {
        this.list = list;
    }

    public Page(Integer pageNo, Integer pageSize, long total) {
        pageNo = (pageNo == null) ? DEFAULT_PAGE_NO : pageNo;
        pageSize = (pageSize == null) ? DEFAULT_PAGE_SIZE : pageSize;
        this.beginPos = (pageNo - 1) * pageSize;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = (int) (total + pageSize - 1) / pageSize;
    }

    public Page(List<T> list, Integer pageNo, Integer pageSize, long total) {
        this.list = list;
        this.pageNo = pageNo;
        this.setPageSize(pageSize);
        this.setTotal(total);
        this.pages = (int) (total + pageSize - 1) / pageSize;
    }

    public Page() {
        new Page<T>(new ArrayList<T>(), 0, 0, 0);
    }

    public void setPage(Integer pageNo, Integer pageSize, long total) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.total = total;
    }

    public static Integer getDefaultPageSize() {
        return DEFAULT_PAGE_SIZE;
    }

    public static void setDefaultPageSize(Integer defaultPageSize) {
        DEFAULT_PAGE_SIZE = defaultPageSize;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getPages() {
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }

    public Integer getBeginPos() {
        return beginPos;
    }

    public void setBeginPos(Integer beginPos) {
        this.beginPos = beginPos;
    }
}
